<template>
  <div class="contenShow">
    <div class="car_lis">
      <template v-for="(item, index) in selectProvince">
        <div class="crile" v-if="index == 2" :key="index">·</div>
        <div class="proivesBtn" :class="selectInd == index ? 'sd' : ''" @click="provincesShowTap(index)" :key="index">
          <span>{{ item }}</span>
          <div class="cursor"></div>
        </div>
      </template>
    </div>
    <div class="radio_line flex" style="justify-content: space-between;margin-top: 1rem;">
      <van-radio-group v-model="radio" direction="horizontal" @change='changeRadioT'>
        <van-radio name="0" checked-color="#FE5E56">汽车</van-radio>
        <van-radio name="1" checked-color="#FE5E56">摩托车</van-radio>
      </van-radio-group>
      <div class="Appeal" @click="to_carAppeal_list">
        <span>车辆申诉</span>
        <i class="iconfont icon-icon_more11"></i>
      </div>
    </div>
    <div class="radio_line">
      <van-radio-group v-model="licensePlate" direction="horizontal">
        <van-radio name="0" checked-color="#FE5E56" v-show="radio !='1'">绿牌</van-radio>
        <van-radio name="1" checked-color="#FE5E56">蓝牌</van-radio>
        <van-radio name="2" checked-color="#FE5E56">黄牌</van-radio>
      </van-radio-group>
    </div>
    <van-popup v-model="provincesShow" :overlay="false" position="bottom" round closeable @close="isClose">
      <div style="padding: 1rem 0.85rem 0 0.85rem;box-sizing: border-box;">
        <car_number_keyboard @clickChild="clickChild" @delete="child_Delete" :ind="selectInd" :show="provincesShow" :keyboardType="keyboardType"></car_number_keyboard>
      </div>
    </van-popup>
  </div>
</template>
<script>
import car_number_keyboard from "./car-number-keyboard.vue";
export default {
  data() {
    return {
      selectProvince: ["", "", "", "", "", "", "", ""],
      radio: "0",
      licensePlate: "0",
      keyboardType: 1,
      selectInd: null,
      provincesShow: false
    };
  },
  components: { car_number_keyboard },
  watch: {
    listChange: function(nval, oval) {
      if (nval) {
        this.selectProvince = ["", "", "", "", "", "", "", ""];
      } else {
        this.selectProvince = ["", "", "", "", "", "", ""];
      }
    }
  },
  computed: {
    listChange() {
      const { radio, licensePlate } = this;
      if (radio == "0" && licensePlate == "0") {
        return true;
      } else {
        return false;
      }
    }
  },
  methods: {
    changeRadioT(){
      if(this.radio == '1' && this.licensePlate == '0') this.licensePlate = '1';
    },
    // 组件数据验证返回
    validation() {
      let res = {
        status: 1, //1是通过验证
        radio: this.radio,
        licensePlate: this.licensePlate
      };
      return new Promise((resolve, reject) => {
        for (let i = 0; i < this.selectProvince.length; i++) {
          if (this.fun.isTextEmpty(this.selectProvince[i])) {
            // 车牌号码其中一处为空
            res.status = 0;
            break;
          }
        }
        if (res.status) {
          res.carNumber = [...this.selectProvince].join("");
        }
        resolve(res);
      });
    },
    to_carAppeal_list() {
      this.$router.push(this.fun.getUrl("carAppeal_list", {}));
    },
    isClose() {
      this.provincesShow = false;
      this.keyboardType = 1;
      this.selectInd = null;
      this.show = false;
    },
    provincesShowTap(index) {
      this.provincesShow = true;
      this.selectInd = index;
      if (index == 0) {
        this.keyboardType = 1;
      } else if (index > 0) {
        this.keyboardType = 2;
      }
    },
    clickChild(e) {
      this.$set(this.selectProvince, e.ind, e.key);
      console.log(e.ind, this.selectProvince.length);
      if (e.ind < this.selectProvince.length - 1) {
        this.selectInd = e.ind + 1;
        if (this.selectInd == 0) {
          this.keyboardType = 1;
        } else if (this.selectInd > 0) {
          this.keyboardType = 2;
        }
      }
      let status = false;
      for (let i = 0; i < this.selectProvince.length; i++) {
        if (this.fun.isTextEmpty(this.selectProvince[i])) {
          status = true;
        }
      }
      if (!status) this.provincesShow = false;
      console.log(status);
    },
    child_Delete(e) {
      console.log(this.selectProvince);
      this.$set(this.selectProvince, e.ind, "");
    }
  }
};
</script>
<style lang="scss" scoped>
.Appeal {
  display: flex;
  align-items: center;
  color: #f15353;
  font-size: 0.88rem;
}
.contenShow {
  padding: 0.94rem 1.09rem;
  border-radius: 0.5rem;
  background: #ffffff;
  margin: 0.625rem;
  .radio_line {
    margin-top: 0.56rem;
  }
  .car_lis {
    display: flex;
    align-items: center;
    justify-content: space-around;
  }
  input,
  .proivesBtn {
    border: 0.03rem solid #d6d6dc;
    width: 2.19rem;
    height: 2.19rem;
    background: #ffffff;
    border-radius: 0.5rem;
    margin-right: 0.25rem;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
  }
  .sd {
    border: 1px solid #0099ff;
    box-shadow: 0px 0px 10px #0099ff;
    position: relative;
    .cursor {
      width: 0.0625rem;
      height: 0.9375rem;
      background-color: #0099ff;
      animation: flashing 1.2s infinite steps(1, start);
    }
  }
  @keyframes flashing {
    0%,
    100% {
      background-color: #0099ff;
    }

    50% {
      background-color: transparent;
    }
  }

  .proivesBtn {
    flex-shrink: 0;
  }
  .proivesBtn:nth-child(2) {
    margin-right: 0;
  }

  .crile {
    font-size: 1rem;
    border: 1rem;
    font-weight: bold;
    margin: 0 0.63rem;
  }
}
</style>
